package com.wannengbang.cloudleader.homepage.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.bean.TeamRewardListBean;
import com.wannengbang.cloudleader.bean.UserInfoBean;
import com.wannengbang.cloudleader.homepage.TeamDetailsListActivity;
import com.wannengbang.cloudleader.utils.SPManager;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 合伙人列表
 */
public class TeamBuyListAdapter extends RecyclerView.Adapter<TeamBuyListAdapter.ViewHolder> {

    private List<TeamRewardListBean.DataBean.ItemListBean> listsBeans;
    private Context context;

    public TeamBuyListAdapter(List<TeamRewardListBean.DataBean.ItemListBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_team_buy_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        TeamRewardListBean.DataBean.ItemListBean dataBean = listsBeans.get(position);

        holder.tvQuotaNum.setText("名额数量：" + dataBean.getQuota());
        holder.tvFulfilNum.setText("已完成数量：" + dataBean.getFulfil());
        holder.tvStartDate.setText("购买日期：" + dataBean.getStart_date());
        holder.tvEndDate.setText("截止日期：" + dataBean.getEnd_date());

        holder.itemView.setOnClickListener(v -> {
            Intent intent = new Intent(context, TeamDetailsListActivity.class);
            intent.putExtra("QuotaNum", dataBean.getQuota());
            intent.putExtra("FulfilNum", dataBean.getFulfil());
            intent.putExtra("team_id", dataBean.getId() + "");
            context.startActivity(intent);
        });
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_quota_num)
        TextView tvQuotaNum;
        @BindView(R.id.tv_fulfil_num)
        TextView tvFulfilNum;
        @BindView(R.id.tv_start_date)
        TextView tvStartDate;
        @BindView(R.id.tv_end_date)
        TextView tvEndDate;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
